package com.zero.guava.samples.CollectionsDemo;

import com.google.common.base.Functions;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSortedMap;
import com.google.common.collect.Ordering;

import java.util.Map;

public class MapOrderingDemo {

    public static void main(String[] args) {

        Map<String, String> map = ImmutableMap.of(
                "per_ue_mac_harq_dl_ack_qpsk", "5",
                "per_ue_mac_harq_dl_ack_16_qam", "4",
                "per_ue_mac_harq_dl_ack_64_qam", "6",
                "per_ue_mac_harq_dl_ack_256_qam", "3");

        final Ordering<String> naturalReverseValueOrdering =
                Ordering.natural().reverse().nullsLast().onResultOf(Functions.forMap(map, null));

        ImmutableSortedMap<String, String> sortedMap = ImmutableSortedMap.copyOf(map, naturalReverseValueOrdering);
        String maxKey = sortedMap.firstKey();
        System.out.println(maxKey);
        System.out.println(sortedMap);
        System.out.println(map.get(maxKey));
    }
}
